<template>
  <div class="new">
    <van-overlay :show="overlayShow" :z-index="1000">
      <div style="display: flex;align-items: center;justify-content: center;height: 100%;">
        <van-loading type="spinner" color="#1989fa">请稍候...</van-loading>
      </div>
    </van-overlay>
    <div style="margin-bottom: 10vh;">
      <van-collapse v-model="activeNames">
        <van-collapse-item v-for="item in jsondata.head" :key="item.grouptitle" :name="item.grouptitle" :title="item.grouptitle">
          <van-cell-group style="border:0px;">
            <div style="border-bottom:1px solid #ebedf0" v-for="itemdata in item.groupvalue" :key="itemdata.ID">
              <div v-if="itemdata.sUIType == 'datetime'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" v-model="itemdata.value" required disabled clearable :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field :id="itemdata.sField" v-model="itemdata.value" readonly required clearable :label="itemdata.sTitle" @click="openDatePicker(itemdata)" :error-message="itemdata.errormsg" placeholder="请输入" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" v-model="itemdata.value" disabled clearable :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field :id="itemdata.sField" v-model="itemdata.value" readonly clearable :label="itemdata.sTitle" @click="openDatePicker(itemdata)" :error-message="itemdata.errormsg" placeholder="请输入" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'code'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field :id="itemdata.sField" clearable v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" placeholder="请输入" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'enum' && itemdata.sUITypeExp == 'normal'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" readonly required v-model="itemdata.value" :label="itemdata.sTitle" @click="openEnum(itemdata)" :error-message="itemdata.errormsg" placeholder="请输入" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" readonly v-model="itemdata.value" :label="itemdata.sTitle" @click="openEnum(itemdata)" :error-message="itemdata.errormsg" placeholder="请输入" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'enum' && itemdata.sUITypeExp == 'multi'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" required v-model="itemdata.value" :label="itemdata.sTitle" @click="openEnumMulti(itemdata)" :error-message="itemdata.errormsg" placeholder="请输入" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" readonly v-model="itemdata.value" :label="itemdata.sTitle" @click="openEnumMulti(itemdata)" :error-message="itemdata.errormsg" placeholder="请输入" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'ref' && itemdata.sUITypeExp == 'normal'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" required clearable v-model="itemdata.value" :label="itemdata.sTitle" right-icon="search" @input="clearRefValue(itemdata)" @clear="clearRefValue(itemdata)" @change="openRef(itemdata, 'headdata', '', 0)" @click-right-icon="openRef(itemdata, 'headdata', '', 0)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" clearable v-model="itemdata.value" :label="itemdata.sTitle" right-icon="search" @input="clearRefValue(itemdata)" @clear="clearRefValue(itemdata)" @change="openRef(itemdata, 'headdata', '', 0)" @click-right-icon="openRef(itemdata, 'headdata', '', 0)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'ref' && itemdata.sUITypeExp == 'multi'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" required clearable v-model="itemdata.value" :label="itemdata.sTitle" right-icon="search" @input="clearRefValue(itemdata)" @clear="clearRefValue(itemdata)" @click-right-icon="openRefMulti(itemdata, 'headdata', '', 0)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" clearable v-model="itemdata.value" :label="itemdata.sTitle" right-icon="search" @input="clearRefValue(itemdata)" @clear="clearRefValue(itemdata)" @click-right-icon="openRefMulti(itemdata, 'headdata', '', 0)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'bool'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_bool'" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_bool'" required v-model="itemdata.value" :label="itemdata.sTitle" @click="openBool(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_bool'" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_bool'" v-model="itemdata.value" :label="itemdata.sTitle" @click="openBool(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'file'">
                <template v-if="itemdata.lMustInput === '0'">
                  <div style="color:#323233;font-size:14px;line-height:24px;padding:5px;">{{ itemdata.sTitle }}</div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader placeholder="请选择文件" v-model="itemdata.valuelist" :after-read="onFileHead" @delete="delFileHead" accept="*" multiple :name="itemdata.sField">
                  </van-uploader>
                </template>

                <template v-if="itemdata.lMustInput === '1'">
                  <div style="color:#323233;font-size:14px;line-height:24px;padding:5px;"><span style="color:red">*</span>{{ itemdata.sTitle }}</div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader placeholder="请选择文件" v-model="itemdata.valuelist" :after-read="onFileHead" @delete="delFileHead" accept="*" multiple :name="itemdata.sField">
                  </van-uploader>
                </template>

              </div>
              <div v-else-if="itemdata.sUIType == 'picture'">

                <template v-if="itemdata.lMustInput === '0'">
                  <div style="color:#323233;font-size:14px;line-height:24px;padding:5px;">{{ itemdata.sTitle }}</div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader v-model="itemdata.valuelist" capture="camera" :deletable="false" :after-read="onImageHead" accept="image/*" multiple :name="itemdata.sField" disabled>
                  </van-uploader>
                </template>

                <template v-if="itemdata.lMustInput === '1'">
                  <div style="color:#323233;font-size:14px;line-height:24px;padding:5px;"><span style="color:red">*</span>{{ itemdata.sTitle }}</div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader placeholder="请选择图片" v-model="itemdata.valuelist" capture="camera" :after-read="onImageHead" @delete="delImageHead" accept="image/*" multiple :name="itemdata.sField">
                  </van-uploader>
                </template>

              </div>
              <div v-else-if="itemdata.sUIType == 'string' && (itemdata.sUITypeExp == 'long' || itemdata.sUITypeExp == 'big')">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field type="textarea" rows="1" autosize :id="itemdata.sField" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" type="textarea" rows="1" autosize :id="itemdata.sField" required v-model="itemdata.value" :label="itemdata.sTitle" @input="checkData(itemdata)" @blur="checkData(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field type="textarea" rows="1" autosize :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" type="textarea" rows="1" autosize :id="itemdata.sField" v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'string' && itemdata.sUITypeExp == 'normal' && itemdata.sFormat == 'yearmonth;'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" :id="itemdata.sField" required v-model="itemdata.value" :label="itemdata.sTitle" @click="openYearMonth(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" :id="itemdata.sField" v-model="itemdata.value" :label="itemdata.sTitle" @click="openYearMonth(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'string' && itemdata.sUITypeExp == 'normal' && itemdata.sFormat.indexOf('refer:') >= 0">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" :id="itemdata.sField" required readonly v-model="itemdata.value" :label="itemdata.sTitle" @click="openRefer(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" :id="itemdata.sField" v-model="itemdata.value" readonly :label="itemdata.sTitle" @click="openRefer(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'map'">
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled :value="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请选择" :id="itemdata.sField" required :value="itemdata.value" :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata)" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled :value="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请选择" :id="itemdata.sField" clearable :value="itemdata.value" :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata)" />
                </template>
              </div>
              <div v-else>
                <template v-if="itemdata.lCanOutput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" :id="itemdata.sField" required clearable v-model="itemdata.value" :label="itemdata.sTitle" @input="checkData(itemdata)" @blur="checkData(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" :id="itemdata.sField" clearable v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
              </div>
            </div>
          </van-cell-group>
        </van-collapse-item>
      </van-collapse>
    </div>
    <van-popup v-model="datepickershow" round position="bottom">
      <van-datetime-picker v-model="currentDate" type="date" @confirm="selectedDate" />
    </van-popup>
    <van-popup v-model="datetimeshow" round position="bottom">
      <van-datetime-picker v-model="currentDate" type="datetime" @confirm="selectedDateTime" />
    </van-popup>
    <van-popup v-model="yearmonthshow" round position="bottom">
      <van-datetime-picker v-model="currentYearMonth" type="year-month" @confirm="selectedYearMonth" />
    </van-popup>
    <van-action-sheet v-model="enumshow" :actions="actions" @select="selectedEnum" />
    <van-popup v-model="enumMultishow" round position="bottom">
      <van-checkbox-group v-model="selecteddata" ref="checkboxGroup">
        <van-cell v-for="(item, index) in enumMulti" :key="item.id" :title="item.name" @click="toggle(index)">
          <van-checkbox :name="item" ref="checkboxes" slot="right-icon" />
        </van-cell>
      </van-checkbox-group>
      <div style="text-align:right;padding-right:10vw;padding-top:2vh;padding-bottom:2vh;">
        <van-button type="info" size="small" @click="selectedEnumMulti">确认</van-button>
      </div>
    </van-popup>
    <van-tabbar v-model="active" safe-area-inset-bottom>
      <van-tabbar-item @click="save">保存</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import Vue from 'vue'
import { Search, List, Cell, PullRefresh, Toast, Tabbar, TabbarItem, Popup, DatetimePicker, ActionSheet, Tab, Tabs, Collapse, CollapseItem, CheckboxGroup, Checkbox, Uploader, Overlay, Loading } from 'vant'
import qs from 'qs'
import wx from 'weixin-js-sdk'
import * as dd from 'dingtalk-jsapi'
Vue.use(Search).use(List).use(Cell).use(PullRefresh).use(Toast).use(Tabbar).use(TabbarItem).use(Popup).use(DatetimePicker).use(ActionSheet).use(Tab).use(Tabs).use(Collapse).use(CollapseItem).use(CheckboxGroup).use(Checkbox).use(Uploader).use(Overlay).use(Loading)
export default {
  name: 'activitybfjl',
  data () {
    return {
      idobject: this.$route.query.idobject,
      idtemplate: this.$route.query.idtemplate,
      itemid: this.$route.query.itemid,
      fromobject: this.$route.query.fromobject,
      jsondata: {},
      index: 0,
      active: 0,
      activeNames: [''],
      activeBodyNams: [''],
      datepickershow: false,
      currentDate: new Date(),
      yearmonthshow: false,
      datetimeshow: false,
      currentYearMonth: new Date(),
      enumshow: false,
      actions: [],
      clickmodel: {},
      isLoad: false,
      conditionValHidden: '',
      clickfrom: '',
      clickindexName: '',
      clickindex: 0,
      selecteddata: [],
      enumMultishow: false,
      enumMulti: [],
      isDisable: false,
      overlayShow: false,
      saveBs: 'new',
      buttonName1: '抵达',
      buttonName2: '离开',
      submittedByButton: false
    }
  },
  mounted: function () {
    //console.log('start created')
    if (!this.isLoad) {
      let data = {
        idtemplate: this.idtemplate
      }
      data[this.idobject + '_id'] = this.itemid
      this.axios({
        method: 'post',
        url: '/api/' + this.idobject + '.bfjl.do',
        data: qs.stringify(data)
      }).then(res => {
        //console.log(res)
        if (res.data.flag === '1') {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        } else {
          this.jsondata = res.data.jsondata
          for (let i = 0; i < res.data.jsondata.head.length; i++) {
            this.activeNames.push(res.data.jsondata.head[i].grouptitle)
          }
          //console.log(this.jsondata)
          this.isLoad = true
        }
      }).catch(res => {
        this.reserror(res)
      })
    }
  },
  methods: {
    save () {
      if (!this.isDisable) {
        this.isDisable = true
        this.overlayShow = true
        let data = {}
        let cansave = 1
        data[this.idobject + '_id'] = this.jsondata[this.idobject + '_id']
        data[this.idobject + '_idtemplate'] = this.idtemplate
        for (let groupindex in this.jsondata.head) {
          let itemgroup = this.jsondata.head[groupindex].groupvalue
          for (let itemindex in itemgroup) {
            let itemdata = itemgroup[itemindex]
            if (itemdata.sUIType === 'ref') {
              if (itemdata.lMustInput === '1' && itemdata.value === '') {
                itemdata.errormsg = '不能为空'
                cansave = 0
              }
              data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
              data[itemdata.idObject + '_' + itemdata.sField + '_ref'] = itemdata.value
            } else if (itemdata.sUIType === 'enum') {
              if (itemdata.lMustInput === '1' && itemdata.value === '') {
                itemdata.errormsg = '不能为空'
                cansave = 0
              }
              data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
              data[itemdata.idObject + '_' + itemdata.sField + '_enum'] = itemdata.value
            } else if (itemdata.sUIType === 'file' || itemdata.sUIType === 'picture') {
              data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
              data[itemdata.idObject + '_' + itemdata.sField + '_title'] = itemdata.value
            } else {
              if (itemdata.lMustInput === '1' && itemdata.value === '') {
                itemdata.errormsg = '不能为空'
                cansave = 0
              }
              data[itemdata.idObject + '_' + itemdata.sField] = itemdata.value
            }
          }
        }
        if (cansave === 0) {
          this.isDisable = false
          this.overlayShow = false
          return
        }

        let sendUrl = '/api/' + this.idobject + '.editsave.do'
        data[this.idobject + '_id'] = this.itemid
        this.axios({
          method: 'post',
          url: sendUrl,
          data: qs.stringify(data)
        }).then(res => {
          this.isDisable = false
          this.overlayShow = false
          if (res.data.flag === '0') {
            this.submittedByButton = true
            Toast('保存成功')
            this.$router.push({ name: 'card', query: { itemid: this.itemid, idobject: this.idobject, fromobject: this.fromobject, idtemplate: this.idtemplate } })
            // this.$router.push({ name: 'bizcalendar' })
          } else {
            Toast(res.data.des)
            if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
              this.loginout()
            }
          }
          //console.log(res)
        }).catch(res => {
          this.isDisable = false
          this.overlayShow = false
          //console.log(res)
        })
      }
    },
    saveTimeAndAddress (bs) {
      let data = {}
      data[this.idobject + '_id'] = this.jsondata[this.idobject + '_id']
      data[this.idobject + '_idtemplate'] = this.idtemplate
      for (let groupindex in this.jsondata.head) {
        let itemgroup = this.jsondata.head[groupindex].groupvalue
        for (let itemindex in itemgroup) {
          let itemdata = itemgroup[itemindex]
          if (itemdata.sUIType === 'ref') {
            data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
            data[itemdata.idObject + '_' + itemdata.sField + '_ref'] = itemdata.value
          } else if (itemdata.sUIType === 'enum') {
            data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
            data[itemdata.idObject + '_' + itemdata.sField + '_enum'] = itemdata.value
          } else if (itemdata.sUIType === 'file' || itemdata.sUIType === 'picture') {
            data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
            data[itemdata.idObject + '_' + itemdata.sField + '_title'] = itemdata.value
          } else {
            data[itemdata.idObject + '_' + itemdata.sField] = itemdata.value
          }
        }
      }
      let sendUrl = '/api/' + this.idobject + '.begin.do'
      if (bs === 'end') {
        sendUrl = '/api/' + this.idobject + '.end.do'
      }
      this.axios({
        method: 'post',
        url: sendUrl,
        data: qs.stringify(data)
      }).then(res => {
        if (res.data.flag === '0') {
          data[this.idobject + '_id'] = res.data.saveid
          //console.log(data[this.idobject + '_id'] + '新id')
        } else {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        }
        //console.log(res)
      }).catch(res => {
        //console.log(res)
      })
    },
    savesubmit () {
      let data = {}
      this.axios({
        method: 'post',
        url: '/api/' + this.idobject + '.newsavesubmit.do',
        data: qs.stringify(data)
      }).then(res => {
        if (data.jsondata.flag === '0') {
          Toast('保存成功')
          // 跳转页面
          this.$router.push({ name: 'list' })
        } else {
          Toast(data.jsondata.des)
        }
      }).catch(res => {
        //console.log(res)
      })
    },
    begin () {
      if (this.buttonName1 === '抵达') {
        for (let groupindex in this.jsondata.head) {
          let itemgroup = this.jsondata.head[groupindex].groupvalue
          for (let itemindex in itemgroup) {
            let itemdata = itemgroup[itemindex]
            if (itemdata.sField === 'sname') {
              if (itemdata.value === '') {
                Toast('请输入主题')
                return
              }
            }
          }
        }
        this.getlocation('begin')
        this.saveBs = 'edit'
      }
    },
    end () {
      if (this.buttonName1 === '抵达') {
        Toast('请先进行抵达操作')
        return
      }
      if (this.buttonName2 === '离开') {
        this.getlocation('end')
      }
    },
    getlocation (type1) {
      let ua = window.navigator.userAgent.toLowerCase()
      let logintype = 'wechat'
      let tourl = window.location.href
      if (ua.indexOf('wxwork') !== -1) {
      } else {
        logintype = 'dingding'
        tourl = window.location.protocol + '//' + window.location.host + '/vue-common/dist/main'
      }
      let _this = this
      let data = {
        url: tourl,
        type: logintype
      }
      let url = '/api/' + this.idobject + '.getlocation.do'
      this.axios({
        method: 'post',
        url: url,
        data: qs.stringify(data)
      }).then(res => {
        if (res.data.flag === '1' && res.data.des && res.data.des.indexOf('登录过期') >= 0) {
          Toast(res.data.des)
          this.loginout()
        } else {
          var data = res.data
          if (logintype === 'wechat') {
            wx.config({
              beta: true,
              debug: false,
              appId: data.appId,
              timestamp: data.timestamp,
              nonceStr: data.nonceStr,
              signature: data.signature,
              jsApiList: [
                'chooseImage',
                'previewImage',
                'uploadImage',
                'downloadImage',
                'previewFile',
                'getLocation'
              ]
            })
            wx.getLocation({
              isHighAccuracy: true,
              type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
              success: function (res) {
                var latitude = res.latitude // 纬度，浮点数，范围为90 ~ -90
                var longitude = res.longitude // 经度，浮点数，范围为180 ~ -180。
                for (let groupindex in _this.jsondata.head) {
                  for (let itemindex in _this.jsondata.head[groupindex].groupvalue) {
                    let item = _this.jsondata.head[groupindex].groupvalue[itemindex]
                    if (type1 === 'begin') {
                      if (item.sField === 'baddress') {
                        item.value = longitude + ',' + latitude
                      }
                      if (item.sField === 'dbegin') {
                        let _currenttime = _this.currenttime()
                        item.value = _currenttime
                        _this.buttonName1 = _currenttime.split(' ')[1].substring(0, 5)
                      }
                    } else if (type1 === 'end') {
                      if (item.sField === 'dend') {
                        let _currenttime = _this.currenttime()
                        item.value = _currenttime
                        _this.buttonName2 = _currenttime.split(' ')[1].substring(0, 5)
                      }
                      if (item.sField === 'eaddress') {
                        item.value = longitude + ',' + latitude
                      }
                    }
                  }
                }
                _this.saveTimeAndAddress(type1)
              }
            })
          } else {
            dd.config({
              agentId: data.agentid,
              corpId: data.appId,
              timeStamp: data.timestamp,
              nonceStr: data.nonceStr,
              signature: data.signature,
              type: 0,
              jsApiList: [
                'runtime.info',
                'biz.contact.choose',
                'device.notification.confirm',
                'device.notification.alert',
                'device.notification.prompt',
                'biz.ding.post',
                'biz.util.openLink',
                'device.geolocation.get'
              ]
            })
            dd.error(function (error) {
              alert('dd error: ' + JSON.stringify(error))
            })
            dd.ready(function () {
              dd.device.geolocation.get({
                targetAccuracy: 200,
                coordinate: 1,
                withReGeocode: false,
                useCache: true,
                onSuccess: function (result) {
                  var longitude = result.longitude
                  var latitude = result.latitude
                  for (let groupindex in _this.jsondata.head) {
                    for (let itemindex in _this.jsondata.head[groupindex].groupvalue) {
                      let item = _this.jsondata.head[groupindex].groupvalue[itemindex]
                      if (type1 === 'begin') {
                        if (item.sField === 'baddress') {
                          item.value = longitude + ',' + latitude
                        }
                        if (item.sField === 'dbegin') {
                          let _currenttime = _this.currenttime()
                          item.value = _currenttime
                          _this.buttonName1 = _currenttime.split(' ')[1].substring(0, 5)
                        }
                      } else if (type1 === 'end') {
                        if (item.sField === 'dend') {
                          let _currenttime = _this.currenttime()
                          item.value = _currenttime
                          _this.buttonName2 = _currenttime.split(' ')[1].substring(0, 5)
                        }
                        if (item.sField === 'eaddress') {
                          item.value = longitude + ',' + latitude
                        }
                      }
                    }
                  }
                  _this.saveTimeAndAddress(type1)
                },
                onfail: function (err) {
                  alert(err.errorMessage)
                }
              })
            })
          }
        }
      }).catch(function (error) {
        alert(error)
      })
    },
    change (t) {
      if (t < 10) {
        return '0' + t
      } else {
        return t
      }
    },
    currenttime () {
      let d = new Date()
      let year = d.getFullYear()
      let month = this.change(d.getMonth() + 1)
      let day = this.change(d.getDate())
      let hour = this.change(d.getHours())
      let minute = this.change(d.getMinutes())
      let second = this.change(d.getSeconds())
      let time = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
      return time
    },
    addRow (indexName) {
      let bodycopy = JSON.parse(JSON.stringify(this.jsondata.body[indexName]))
      this.jsondata.bodydata[indexName].push(bodycopy)
    },
    delRow (indexName, index) {
      if (this.jsondata.bodydata[indexName].length === 1) {
        Toast('至少保留一条表体行，不能删除！')
        return
      }
      this.jsondata.bodydata[indexName].splice(index, 1)
    },
    checkData (datamodel) {
      if (datamodel.value === '') {
        datamodel.errormsg = '不能为空'
      } else {
        datamodel.errormsg = ''
      }
    },
    openDatePicker (datamodel) {
      if (datamodel.value != null && datamodel.value !== undefined && datamodel.value !== '') {
        if (datamodel.sUITypeExp !== 'long') {
          datamodel.value = datamodel.value.substring(0, 10)
        }
        let newDate = new Date(datamodel.value.replace(/-/g, '/'))
        this.currentDate = new Date(newDate)
      }
      this.clickmodel = datamodel
      if (datamodel.sUITypeExp === 'long') {
        this.datetimeshow = true
      } else {
        this.datepickershow = true
      }
    },
    selectedDate () {
      //console.log(this.currentDate)
      let year = this.currentDate.getFullYear() // 获取完整的年份(4位,1970-????)
      let month = this.currentDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
      let day = this.currentDate.getDate() // 获取当前日(1-31)
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = '0' + day
      }
      let dateString = year + '-' + month + '-' + day
      this.clickmodel.value = dateString
      this.clickmodel.errormsg = ''
      this.datepickershow = false
    },
    selectedDateTime () {
      //console.log(this.currentDate)
      let year = this.currentDate.getFullYear() // 获取完整的年份(4位,1970-????)
      let month = this.currentDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
      let day = this.currentDate.getDate() // 获取当前日(1-31)
      let hour = this.currentDate.getHours()
      let minute = this.currentDate.getMinutes()
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = '0' + day
      }
      if (hour < 10) {
        hour = '0' + hour
      }
      if (minute < 10) {
        minute = '0' + minute
      }
      let dateString = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':00'
      this.clickmodel.value = dateString
      this.clickmodel.errormsg = ''
      this.datetimeshow = false
    },
    openYearMonth (datamodel) {
      if (datamodel.value != null && datamodel.value !== undefined && datamodel.value !== '') {
        datamodel.value = datamodel.value.substring(0, 7)
        this.currentYearMonth = new Date(datamodel.value)
      }
      this.clickmodel = datamodel
      this.yearmonthshow = true
    },
    selectedYearMonth () {
      //console.log(this.currentYearMonth)
      let year = this.currentYearMonth.getFullYear()
      let month = this.currentYearMonth.getMonth() + 1
      if (month < 10) {
        month = '0' + month
      }
      let datestring = year + '-' + month
      this.clickmodel.value = datestring
      this.clickmodel.errormsg = ''
      this.yearmonthshow = false
    },
    openEnum (datamodel) {
      this.actions = []
      this.clickmodel = datamodel
      let enumid = datamodel.allenumid
      let arrEnumid = enumid.split(';')
      let enumval = datamodel.allenumval
      let arrEnumval = enumval.split(';')
      for (let i = 0; i < arrEnumid.length; i++) {
        this.actions.push({ id: arrEnumid[i], name: arrEnumval[i] })
      }
      this.enumshow = true
    },
    selectedEnum (item) {
      this.clickmodel.valuehidden = item.id
      this.clickmodel.value = item.name
      this.clickmodel.errormsg = ''
      this.enumshow = false
    },
    openEnumMulti (datamodel) {
      this.enumMulti = []
      this.selecteddata = []
      this.clickmodel = datamodel
      let enumid = datamodel.allenumid
      let arrEnumid = enumid.split(';')
      let enumval = datamodel.allenumval
      let arrEnumval = enumval.split(';')
      for (let i = 0; i < arrEnumid.length; i++) {
        if (arrEnumid[i] === '') {
          continue
        }
        this.enumMulti.push({ id: arrEnumid[i], name: arrEnumval[i] })
      }
      this.enumMultishow = true
    },
    toggle (index) {
      this.$refs.checkboxes[index].toggle()
    },
    selectedEnumMulti () {
      let enumid = ''
      let enumval = ''
      this.clickmodel.valuehidden = ''
      this.clickmodel.value = ''
      for (let i = 0; i < this.selecteddata.length; i++) {
        enumid += this.selecteddata[i].id + ';'
        enumval += this.selecteddata[i].name + ';'
      }
      this.clickmodel.valuehidden = enumid
      this.clickmodel.value = enumval
      this.clickmodel.errormsg = ''
      this.enumMultishow = false
    },
    openRefer (datamodel) {
      this.actions = []
      this.clickmodel = datamodel
      let referVal = datamodel.sFormat.substring(6, datamodel.sFormat.length - 1)
      let arrRefer = referVal.split(',')
      for (let i = 0; i < arrRefer.length; i++) {
        this.actions.push({ id: arrRefer[i], name: arrRefer[i] })
      }
      this.enumshow = true
    },
    openBool (datamodel) {
      this.actions = []
      this.clickmodel = datamodel
      this.actions.push({ id: '1', name: '是' })
      this.actions.push({ id: '0', name: '否' })
      this.enumshow = true
    },
    openRef (datamodel, datafrom, indexName, index) {
      this.clickmodel = datamodel
      this.clickfrom = datafrom
      this.clickindexName = indexName
      this.clickindex = index
      this.conditionValHidden = ''
      let inview = datamodel.inview
      if (inview !== '') {
        let arrinview = inview.split(';')
        for (let inviewindex in arrinview) {
          let arrinviewdata = arrinview[inviewindex]
          let inviewdatas = arrinviewdata.split(':')
          if (inviewdatas[1] === 'eq') {
            if (datafrom === 'headdata') {
              for (let groupindex in this.jsondata.head) {
                for (let itemindex in this.jsondata.head[groupindex].groupvalue) {
                  let item = this.jsondata.head[groupindex].groupvalue[itemindex]
                  if (item.sField === inviewdatas[2].split('_')[2]) {
                    this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                  }
                }
              }
            } else if (datafrom === 'bodydata') {
              for (let itemindex in this.jsondata.bodydata[indexName][index]) {
                let item = this.jsondata.bodydata[indexName][index][itemindex]
                if (item.sField === inviewdatas[0]) {
                  this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                }
              }
            }
          } else if (inviewdatas[1] === 'in') {
            //console.log('-------------' + datamodel.value)
            this.conditionValHidden += inviewdatas[0] + ':in:' + datamodel.value + ';'
          }
        }
      }
      this.$router.push({
        name: 'ref',
        params: {
          bo: datamodel.idJoinObject,
          tobo: datamodel.idObject,
          field: datamodel.sField,
          fieldref: datamodel.sFieldRef,
          viewid: datamodel.sRefKey,
          conditionVal: '',
          conditionValHidden: this.conditionValHidden,
          classname: datamodel.classname
        }
      })
    },
    openMap (data) {
      this.$router.push({
        name: 'map',
        params: {
          sval: this.jsondata.head,
          svalmap: data
        }
      })
    },
    openRefMulti (datamodel, datafrom, indexName, index) {
      this.clickmodel = datamodel
      this.clickfrom = datafrom
      this.clickindexName = indexName
      this.clickindex = index
      this.conditionValHidden = ''
      let inview = datamodel.inview
      if (inview !== '') {
        let arrinview = inview.split(';')
        for (let inviewindex in arrinview) {
          let arrinviewdata = arrinview[inviewindex]
          let inviewdatas = arrinviewdata.split(':')
          if (inviewdatas[1] === 'eq') {
            if (datafrom === 'headdata') {
              for (let groupindex in this.jsondata.head) {
                for (let itemindex in this.jsondata.head[groupindex].groupvalue) {
                  let item = this.jsondata.head[groupindex].groupvalue[itemindex]
                  if (item.sField === inviewdatas[2].split('_')[2]) {
                    this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                  }
                }
              }
            } else if (datafrom === 'bodydata') {
              for (let itemindex in this.jsondata.bodydata[indexName][index]) {
                let item = this.jsondata.bodydata[indexName][index][itemindex]
                if (item.sField === inviewdatas[0]) {
                  this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                }
              }
            }
          } else if (inviewdatas[1] === 'in') {
            this.conditionValHidden += inviewdatas[0] + ':in:;'
          }
        }
      }
      this.$router.push({
        name: 'refmulti',
        params: {
          bo: datamodel.idJoinObject,
          tobo: datamodel.idObject,
          field: datamodel.sField,
          fieldref: datamodel.sFieldRef,
          viewid: datamodel.sRefKey,
          conditionVal: '',
          conditionValHidden: this.conditionValHidden,
          classname: datamodel.classname
        }
      })
    },
    clearRefValue (datamodel) {
      if (datamodel.value === '') {
        datamodel.valuehidden = ''
      }
    },
    onImageHead (file, detail) {
      // 上传
      let deviceFile = []
      let formData = new FormData()
      if (Array.isArray(file)) {
        deviceFile = file
      } else {
        deviceFile.push(file)
      }
      for (let i = 0; i < deviceFile.length; i++) {
        formData.append('image' + i, deviceFile[i].file, deviceFile[i].name)
      }
      const toast = Toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: '等待上传中...请稍候'
      })

      this.axios({
        method: 'post',
        url: '/api/upload.imagedo',
        data: formData,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then(res => {
        if (res.data.flag === '0') {
          toast.clear()
          let fileInfo = res.data.fileInfo
          for (let headIdx = 0; headIdx < this.jsondata.head.length; headIdx++) {
            let headData = this.jsondata.head[headIdx].groupvalue
            for (let i = 0; i < headData.length; i++) {
              if (headData[i].sField === detail.name) {
                headData[i].valuehidden = fileInfo[0].newname + ';' + headData[i].valuehidden
                headData[i].value = fileInfo[0].oldname + ';' + headData[i].value
              }
            }
          }
          Toast('上传成功')
        } else {
          Toast('上传失败')
        }
      }).catch(res => {
        //console.log(res)
      })
      // let headdata = this.jsondata.head[0].groupvalue
      //console.log(file)
      //console.log(detail)
    },
    delImageHead (file, detail) {
      for (let headIdx = 0; headIdx < this.jsondata.head.length; headIdx++) {
        let headData = this.jsondata.head[headIdx].groupvalue
        for (let i = 0; i < headData.length; i++) {
          if (headData[i].sField === detail.name) {
            let imgVal = headData[i].valuehidden.split(';')
            let imgTitle = headData[i].value.split(';')
            for (let j = 0; j < imgTitle.length; j++) {
              if (imgTitle[j] === file.file.name) {
                imgVal[j] = ''
                imgTitle[j] = ''
              }
            }
            let imgVal1 = ''
            let imgTitle1 = ''
            for (let j = 0; j < imgTitle.length; j++) {
              if (imgTitle[j] !== '') {
                imgVal1 += imgVal[j] + ';'
                imgTitle1 += imgTitle[j] + ';'
              }
            }
            headData[i].valuehidden = imgVal1
            headData[i].value = imgTitle1
          }
        }
      }
      Toast('删除成功')
    },
    onFileHead (file, detail) {
      // 上传
      let deviceFile = []
      let formData = new FormData()
      if (Array.isArray(file)) {
        deviceFile = file
      } else {
        deviceFile.push(file)
      }
      for (let i = 0; i < deviceFile.length; i++) {
        formData.append('file' + i, deviceFile[i].file, deviceFile[i].name)
      }
      this.axios({
        method: 'post',
        url: '/api/upload.filedo',
        data: formData,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then(res => {
        if (res.data.flag === '0') {
          let fileInfo = res.data.fileInfo
          for (let headIdx = 0; headIdx < this.jsondata.head.length; headIdx++) {
            let headData = this.jsondata.head[headIdx].groupvalue
            for (let i = 0; i < headData.length; i++) {
              if (headData[i].sField === detail.name) {
                headData[i].valuehidden = fileInfo[0].newname + ';' + headData[i].valuehidden
                headData[i].value = fileInfo[0].oldname + ';' + headData[i].value
              }
            }
          }
          Toast('上传成功')
        } else {
          Toast('上传失败')
        }
      }).catch(res => {
        //console.log(res)
      })
      // let headdata = this.jsondata.head[0].groupvalue
      //console.log(file)
      //console.log(detail)
    },
    delFileHead (file, detail) {
      for (let headIdx = 0; headIdx < this.jsondata.head.length; headIdx++) {
        let headData = this.jsondata.head[headIdx].groupvalue
        for (let i = 0; i < headData.length; i++) {
          if (headData[i].sField === detail.name) {
            let fileVal = headData[i].valuehidden.split(';')
            let fileTitle = headData[i].value.split(';')
            for (let j = 0; j < fileTitle.length; j++) {
              if (fileTitle[j] === file.file.name) {
                fileVal[j] = ''
                fileTitle[j] = ''
              }
            }
            let fileVal1 = ''
            let fileTitle1 = ''
            for (let j = 0; j < fileTitle.length; j++) {
              if (fileTitle[j] !== '') {
                fileVal1 += fileVal[j] + ';'
                fileTitle1 += fileTitle[j] + ';'
              }
            }
            headData[i].valuehidden = fileVal1
            headData[i].value = fileTitle1
          }
        }
      }
      Toast('删除成功')
    }
  },
  activated () {
    if (this.$store.state.ref_show !== '') {
      this.clickmodel.value = this.$store.state.ref_show
      this.clickmodel.valuehidden = this.$store.state.ref_id
      this.clickmodel.errormsg = ''
      let fieldmap = this.clickmodel.fieldmap
      if (fieldmap !== undefined && fieldmap.length > 0) {
        let arrFieldmap = fieldmap.split(';')
        let item = this.$store.state.ref_item
        if (this.clickfrom === 'headdata') {
          for (let groupindex = 0; groupindex < this.jsondata.head.length; groupindex++) {
            let itemgroup = this.jsondata.head[groupindex]
            for (let itemindex = 0; itemindex < itemgroup.groupvalue.length; itemindex++) {
              let itemdata = itemgroup.groupvalue[itemindex]
              for (let fieldmapindex in arrFieldmap) {
                let arrFieldMapKey = arrFieldmap[fieldmapindex].split(':')
                if (this.$store.state.ref_field === arrFieldMapKey[1]) {
                  continue
                }
                if (itemdata.sField === arrFieldMapKey[1]) {
                  if (itemdata.sUIType === 'ref') {
                    itemdata.value = item[arrFieldMapKey[0] + '_ref']
                    itemdata.valuehidden = item[arrFieldMapKey[0]]
                  } else if (itemdata.sUIType === 'enum') {
                    itemdata.value = item[arrFieldMapKey[0] + '_enum']
                    itemdata.valuehidden = item[arrFieldMapKey[0]]
                  } else {
                    itemdata.value = item[arrFieldMapKey[0]]
                  }
                }
              }
            }
          }
        } else if (this.clickfrom === 'bodydata') {
          for (let itemindex in this.jsondata.bodydata[this.clickindexName][this.clickindex]) {
            let itemdata = this.jsondata.bodydata[this.clickindexName][this.clickindex][itemindex]
            for (let fieldmapindex in arrFieldmap) {
              let arrFieldMapKey = arrFieldmap[fieldmapindex].split(':')
              if (this.$store.state.ref_field === arrFieldMapKey[1]) {
                continue
              }
              if (itemdata.sField === arrFieldMapKey[1]) {
                if (itemdata.sUIType === 'ref') {
                  itemdata.value = item[arrFieldMapKey[0] + '_ref']
                  itemdata.valuehidden = item[arrFieldMapKey[0]]
                } else if (itemdata.sUIType === 'enum') {
                  itemdata.value = item[arrFieldMapKey[0] + '_enum']
                  itemdata.valuehidden = item[arrFieldMapKey[0]]
                } else {
                  itemdata.value = item[arrFieldMapKey[0]]
                }
              }
            }
          }
        }
      }
      this.clickmodel = {}
      this.clickindex = 0
      this.clickindexName = ''
      this.clickfrom = ''
      this.$store.commit('clearRef')
    }
  },
  beforeRouteLeave (to, from, next) {
    //console.log('to.name:' + to.name)
    //console.log('from.name' + from.name)
    // 点击按钮
    if (this.submittedByButton) {
      next()
      return
    }
    if (to.name === 'card') {
      const v = confirm('当前数据未保存,确定退出吗?')
      if (!v) {
        next(false)
      } else {
        next()
      }
    } else {
      next()
    }
  }

}
</script>

<style>
.fieldgroup_title {
  text-align: left;
  margin: 0px;
  padding: 25px 15px 15px;
  color: rgba(69, 90, 100, 0.6);
  font-weight: normal;
  font-size: 14px;
}
</style>
